using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace PUCIT.eFCS.DataAccess.Models.Mapping
{
    public class fieldMap : EntityTypeConfiguration<field>
    {
        public fieldMap()
        {
            // Primary Key
            this.HasKey(t => t.fieldId);

            // Properties
            this.Property(t => t.label)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.htmlFieldId)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.html)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("field");
            this.Property(t => t.fieldId).HasColumnName("fieldId");
            this.Property(t => t.sectionId).HasColumnName("sectionId");
            this.Property(t => t.sequenceNo).HasColumnName("sequenceNo");
            this.Property(t => t.label).HasColumnName("label");
            this.Property(t => t.htmlFieldId).HasColumnName("htmlFieldId");
            this.Property(t => t.html).HasColumnName("html");

            // Relationships
            this.HasRequired(t => t.section)
                .WithMany(t => t.fields)
                .HasForeignKey(d => d.sectionId);

        }
    }
}
